var gulp = require('gulp'),
	less = require('gulp-less'),
	atto = require('gulp-autoprefixer'),
	yaso = require('gulp-minify-css'),
	rmae = require('gulp-rename'),
	sourcemap = require('gulp-sourcemaps'),
 	bs=require('browser-sync');

gulp.task('serve',function(){
	bs.init({
		server:{
			baseDir:"./src"
		},
		startPath:"index.html"
	})
})

gulp.task('less',function(){
	gulp.src('src/less/*.less')
		// .pipe(sourcemap.init() )
		.pipe( less() )
		.pipe( atto({
				browsers:['last 2 versions']
		}) )
		.pipe( gulp.dest('src/css') )
		.pipe( yaso() )
		.pipe( rmae({
				suffix:'.min'
		}) )
		// .pipe(sourcemap.write('./'))
		.pipe(gulp.dest('src/css'))
		.pipe( bs.reload({stream: true}) );
})
gulp.task('watch',['less'],function(){
	gulp.watch('src/less/*.less',['less']);
	gulp.watch('src/*.html',function(){
		bs.reload();
	})
});

// gulp.task('watch',function(){
// 	gulp.watch('src/less/*.less',['less']);
// })
// gulp.task('default',function(){
// 	gulp.start('watch');
// })
 
gulp.task('default',['serve','watch']);